from haystack import indexes
from apps.goods.models import SKU


class SKUIndex(indexes.SearchIndex, indexes.Indexable):
    # 1,配置字段
    text = indexes.CharField(document=True, use_template=True)
    price = indexes.DecimalField(model_attr="price")
    name = indexes.CharField(model_attr="name")
    default_image_url = indexes.CharField(model_attr="default_image_url")
    id = indexes.IntegerField(model_attr="id")

    # 2,在哪个模型类中搜索
    def get_model(self):
        return SKU

    # 3,指定数据集
    def index_queryset(self, using=None):
        "Used when the entire index for model is updated."
        return self.get_model().objects.filter(is_launched=True)
